<template>
  <div>
    <section class="content">
      <div class="container">
        <!-- 面包屑导航star -->
        <el-breadcrumb separator="/" class="breadCrumb_Box">
          <el-breadcrumb-item :to="{ path: '/detailInfoto' }">个人中心</el-breadcrumb-item>
          <el-breadcrumb-item>我的资料</el-breadcrumb-item>
          <el-breadcrumb-item>账号信息</el-breadcrumb-item>
          <el-breadcrumb-item>个人认证-填写资料</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 面包屑导航end -->
        <div class="bigbox">
          <div class="box container-fluid" style="overflow: hidden;">
            <stepTow></stepTow>
            <form class="form-horizontal tableForm" v-loading="loading" element-loading-text="正在上传中 请耐心等待">
              <div class="form-group">
                <label for="inputEmail3" class="label-width control-label label_left" style="padding-right:0px">
                  <span style="color: #FF0707;">* </span>企业名称：
                </label>
                <div class=" col-sm-8 col-md-8 col-lg-8" style="padding-left:0px">
                  <input type="email" style="width: 53%;height: 36px;" class="label-width form-control" id="inputEmail3"
                    v-model="formdata.username" placeholder="请填写您的企业名称" />
                </div>
              </div>
              <div class="form-group">
                <label for="inputEmail3" class="label-width control-label label_left" style="padding-right:0px">
                  <span style="color: #FF0707;">* </span>企业执照：
                </label>
                <div class=" col-sm-8 col-md-8 col-lg-8 zhizhao" style="padding-left:0px">
                  <!-- 企业执照 -->
                  <!-- type=“1” 代表身份证 -->
                  <ossUpload :type="'1'" :module="'realname'" :change="getEnterprise" :success="getEnterprisesuccess"
                    :beforeupload="upimgbeforeupload" class="zhizhao-upload">
                    <!-- <img v-if="imageUrlFace" :src="imageUrlFace" class="avatar" style="width: 185px;height:120px;" />
                    <img v-else src="../../../../static/zc_sf1.jpg" class="avatar" style="width: 185px;height:120px;" /> -->
                    <input v-if="enterpriseImage" type="text" class="label-width form-control"
                      :value="enterpriseImageName" />
                    <input v-else type="text" class=" form-control" placeholder="请上传您的企业执照" />
                  </ossUpload>
                  <p class="enterprise-text">单张照片大小不超过1M，支持PNG、JPG格式，请确保图片清晰</p>
                </div>
              </div>

              <div class="IDfaceBigbox">
                <div class="IDfacebox">
                  <div class="IDface-group">
                    <label for="inputEmail3">
                      <span style="color: #FF0707;">* </span>法人身份证：
                    </label>
                  </div>
                  <div class="IDface ID-two">
                    <ossUpload :type="'1'" :module="'realname'" :change="getIdFace" :success="getIdFacesuccess"
                      :beforeupload="upimgbeforeupload">
                      <img v-if="imageUrlFace" :src="imageUrlFace" class="avatar" style="width: 185px;height:120px;" />
                      <img v-else src="../../../../static/zc_sf1.jpg" class="avatar"
                        style="width: 185px;height:120px;" />
                    </ossUpload>
                  </div>
                  <div class="IDface ID-two">
                    <ossUpload :type="'1'" :change="getIdBack" :success="getIdBacksuccess"
                      :beforeupload="upimgbeforeupload" :module="'realname'">
                      <img v-if="imageUrlBack" :src="imageUrlBack" class="avatar" style="width: 185px;height:120px;" />
                      <img v-else src="../../../../static/zc_sf2.jpg" class="avatar"
                        style="width: 185px;height:120px;" />
                    </ossUpload>
                  </div>
                  <div class="IDface-text" style=" color: #FF0000; font-size: 12px;">
                    应监管部门要求，网上发布APP必须进行实名登记，我们采用了高于行业标准的要求来保障您的信息安全，为了进一步的保护您的个人信息，建议您在上传的实名信息中添加水印文字-仅供实名认证使用。
                  </div>
                </div>

              </div>
              <div class="titleItem">
                <div class="titlelist">
                  <div>1.单张照片大小不超过1M，支持PNG、JPG格式；</div>
                  <div>2.所上传的图片，保证文字和图片、人像清晰可见；</div>
                </div>
              </div>
              <div class="btnbox">
                <!-- <el-button class="btnper" @click="goUrl('/realName', 'realName')">上一步
                </el-button> -->
                <el-button class="btnnext" @click="submitUserMsg(formdata.username, formdata.peopleID)">提交</el-button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>
<script>
  import stepTow from "../../account/uploadID/stepTow.vue";
  import ossUpload from "../../common/OSSUpload";
  import loading from "element-ui";

  let zzic_path = null;
  let zpic_path = null;
  let fpic_path = null;
  export default {
    components: {
      stepTow,
      ossUpload
    },
    data() {
      return {
        imageUrlFace: "", //身份证正面的图片
        imageUrlBack: "", //身份证反面的图片
        enterpriseImage: "", //企业执照图片
        enterpriseImageName: "",
        // 表单中的数据
        formdata: {
          enterprisename: "" //企业名称
        },
        loading: false, //提交认证的弹窗
        getpolicy: "getpolicy",
        realname: "realname"
      };
    },
    methods: {
      upimgbeforeupload(file) {
        console.log(file);
        const isJPG = file.raw.type === "image/jpeg";
        const isPNG = file.raw.type === "image/png";
        const isLt2M = file.size / 1024 / 1024 < 1;
        if (!isJPG && !isPNG) {
          this.$message.error("上传头像图片只能是 JPG  PNG 格式!");
          return false;
        }
        // 如果该文件大于1M 则返回
        if (!isLt2M) {
          this.$message.error("上传头像图片大小不能超过 1MB!");
          return false;
        }
        console.log(isJPG);
        console.log(isPNG);
        console.log(isLt2M);
        return isJPG || (isPNG && isLt2M);
      },
      //获取企业执照图片
      getEnterprise(e) {
        console.log(e)
        this.enterpriseImage = window.URL.createObjectURL(e.raw);
        this.enterpriseImageName = e.name;
      },
      getEnterprisesuccess(res) {
        console.log(res);
        zzic_path = res
      },
      // 获取正面图片
      getIdFace(e) {
        console.log(e);
        this.imageUrlFace = window.URL.createObjectURL(e.raw);
      },
      getIdFacesuccess(res) {
        console.log(res);
        zpic_path = res
      },
      // 获取反面图片
      getIdBack(e) {
        this.imageUrlBack = window.URL.createObjectURL(e.raw);
      },
      getIdBacksuccess(res) {
        console.log(res);
        fpic_path = res
      },

      // 路由跳转
      goUrl(path, name) {
        this.$router.push({
          path: path,
          name: name
        });
      },
      // 提交实名制认证
      submitUserMsg(realName, znum) {


        console.log(znum.length);
        if (realName.length <= 0) {
          this.$message.error("名字不能为空");
          return;
        }
        // if (znum.length < 18) {
        //   this.$message.error("身份证号不正确");
        //   return;
        // }
        if (zzid_path === null) {
          this.$message.error("请上传企业执照");
          return;
        }
        if (zpic_path === null) {
          this.$message.error("请上传身份证正面图片");
          return;
        }
        if (fpic_path === null) {
          this.$message.error("请上传身份证反面图片");
          return;
        }

        this.loading = true;
        var params = new URLSearchParams(); //这种是提交文本数据
        params = new FormData(); //这种是通过form表单提交，可以提交文件
        params.append("realName", String(realName));
        params.append("znum", String(znum));
        params.append("zzic", String(zzic_path));
        params.append("zpic", String(zpic_path));
        params.append("fpic", String(fpic_path));
        this.$post(this.API.SubmitPeopleId, params).then(res => {
          if (res.code == 0) {
            this.loading = false;
          } else {
            this.goUrl("/checkID", "checkID");
          }
        });
      }
    }
  };

</script>
<style scoped>
  .breadCrumb_Box {
    margin-top: 30px;
  }

  .box {
    margin-top: 80px;
  }

  .bigbox {
    width: 100%;
    margin-bottom: 30px;
    background-color: #ffffff;
    overflow: hidden;
    margin-top: 20px;

    box-shadow: 0px 4px 10px 2px rgba(0, 0, 0, 0.08);
  }

  .text1 {
    margin-top: 100px;
    width: 100%;
    font-size: 16px;
    font-weight: 700;
    color: #000;
    text-align: center;
  }

  .text2 {
    width: 100%;
    font-size: 14px;
    font-weight: 300;
    color: #afadad;
    text-align: center;
    margin-top: 5px;
  }

  .tableForm {
    margin-top: 150px;
    overflow: hidden;
  }

  .label_left {
    text-align: right;
  }

  .label_right {
    text-align: left;
  }

  .label-width {
    width: 20%;
    float: left;
  }

  div>>>input[type="file"] {
    display: none;
  }

  .IDfaceBigbox {
    margin-left: -15px;
    margin-right: -15px;
  }

  .IDfacebox {
    width: 100%;
  }

  .IDface {
    display: inline-block;
  }

  .IDfacebox .IDface:nth-child(1) {
    margin-bottom: 14px;
  }

  .IDimg {
    display: inline-block;
    width: 233px;
    height: 271;
    margin-left: 13px;
  }

  .IDimg img {
    width: 233px;
    height: 271px;
    vertical-align: baseline;
  }

  .IDface-group {
    width: 20%;
    padding-top: 7px;
    margin-bottom: 0;
    text-align: right;
    display: inline-block;
    vertical-align: top;
  }

  .IDface-text {
    width: 20%;
    display: inline-block;
    vertical-align: top;
  }

  .zhizhao-upload {
    width: 53%;
    margin-right: 0px;
    display: inline-block;
    vertical-align: bottom;
  }

  .enterprise-text {
    font-size: 12px;
    color: #989898;
    display: inline-block;
    height: 39px;
    line-height: 39px;
    margin: 0px;
    vertical-align: bottom;
  }

  .titleItem {
    display: flex;
    flex-direction: row;
    padding-left: 33.3333%;
    align-items: center;
    margin-top: 10px;
    font-size: 12px;
    color: #989898;
  }

  .titleItem label {
    flex: 4;
    text-align: right;
    margin-right: 15px;
  }

  .titlelist {
    flex: 8;
    text-align: left;
  }

  .btnbox {
    margin-top: 20px;
    margin-bottom: 40px;
    width: 100%;
  }

  .btnper {
    margin-left: 33%;
    width: 110px;
    height: 36px;
    background-color: #b9b9b9;
    color: #fff;
    line-height: 0;
  }

  .btnnext {
    margin-left: 33.333%;
    width: 110px;
    height: 36px;
    background-color: #ff7f3f;
    align-self: flex-start;
    color: #fff;
    line-height: 0;
  }

  /* 图片上传样式 */
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }


  .avatar-uploader .el-upload:hover {
    border-color: #409eff;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    display: block;
    border: 1px solid #e4e4e4;
    border-radius: 5px;
    margin-right: 15px;
  }

  .titleItem {
    padding-left: 20%;
  }

  @media screen and (max-width: 992px) {
    .box {
      margin-top: 20px;
    }

    .text1 {
      margin-top: 40px;
    }

    .bigbox {
      height: auto;
    }

    .tableForm {
      margin-top: 110px;
      overflow: hidden;
    }

    .IDface-text {
      width: 50%;
      margin-left: 20.333%;
    }

    .enterprise-text {
      padding-left: 15px;
    }

    .titleItem {
      padding-left: 20%;
    }

  }

  @media screen and (max-width: 669px) {
    .IDface.ID-two {
      display: block;
      margin-left: 33.3333%;
    }

    .enterprise-text {
      padding-left: 15px;
    }

    .IDface-text {
      width: 50%;
      margin-left: 33.333%;
    }
  }

  @media screen and (max-width: 560px) {
    .IDfaceBigbox {
      width: 100%;
      /* height: 530px; */
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      overflow: hidden;
    }

    .ID-two {
      display: block;
      margin-left: 33.3333%;
    }

    .btnbox {
      width: 100%;
    }

    .btnper {
      margin-left: 13%;
    }

    .IDface-group {
      width: 33%;
    }

    .label-width {
      width: 33%;
    }

    .enterprise-text {
      display: none;
    }
  }

</style>

<style>
  .avatar-uploader .el-upload.el-upload--text {
    width: 100%;
  }

</style>
